package cn.ekuma.epos.android.finder;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import android.app.ProgressDialog;
import android.os.Bundle;
import android.view.View;
import com.openbravo.bean.oa.Attence;
import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.query.QBFParameter;
import com.openbravo.data.loader.query.QBFParameters;

import cn.ekuma.data.ui.android.AbstractViewBeanListAdapter;
import cn.ekuma.data.ui.android.AbstractTimeCycleListenerImplListActivate;
import cn.ekuma.epos.android.adapter.AttenceListAdapter;
import cn.ekuma.epos.datalogic.DataLogicPDA;
import cn.ekuma.epos.datalogic.I_DataLogicERP;
import cn.ekuma.epos.db.table.oa.I_Attence;

public class AttenceFinderActivate extends AbstractTimeCycleListenerImplListActivate<Attence> {

	private String userId;
	public static final String USER_ID="user_id";

    protected AttenceFinderActivate() {
        super(DataLogicPDA.getDataLogic());
    }


    @Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		Bundle mBundle=getIntent().getExtras();
		if(mBundle!=null){
			userId=(String) mBundle.getSerializable(USER_ID);
		}
	}

	@Override
	public AbstractViewBeanListAdapter getListAdapter() {
		return new AttenceListAdapter(this);
	}

	@Override
	public void filterParaReset() {
		quickTimeFilter.resertValues();
		
	}

	@Override
	public void initAdvSeachView() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public boolean isQuickSeachAble() {
		return false;
	}

	public void baseBeanSelected(Attence obj, int position) {
		// TODO Auto-generated method stub
		
	}

	public void timeCycleChanged(Date start, Date end) {
		final QBFParameters paras=new QBFParameters();
		if(start!=null)
		  paras.and(new QBFParameter(I_Attence.CREATEDATE).greaterOrEqual(start));
		if(end!=null)
		  paras.and(new QBFParameter(I_Attence.CREATEDATE).less(end));
		if(userId!=null)
	      paras.and(new QBFParameter(I_Attence.USER_ID).equal(userId));
		final ProgressDialog dialog = ProgressDialog.show(this, "", 
			        "查旬中，请稍等 …", true, true);
			new Thread(){
				public void run(){
					I_DataLogicERP dlERP=DataLogicPDA.getDLERP();
					try {
						List<Attence> lists=dlERP.queryByQBFParameters(Attence.class.getName(), paras);
						if(lists==null)
							lists=new ArrayList();
						mHandler.obtainMessage(MSG_SUCCESS, lists).sendToTarget();			
					} catch (BasicException e) {
						e.printStackTrace();
						mHandler.obtainMessage(MSG_FAILURE).sendToTarget();//获取图片失败   
					}
				dialog.dismiss(); 
			}
		}.start();
	}

	@Override
	public void onQuickSeach(String inputText) {
		// TODO Auto-generated method stub
	}

	@Override
	public View createAdvFilterPanel() {
		// TODO Auto-generated method stub
		return null;
	}
	

}
